package com.string;

public class Solution05 {
    public String reverseLeftWords(String s, int n) {
        char[] chars = s.toCharArray();
        revStr(chars,0, n-1);
        revStr(chars,n, chars.length-1);
        revStr(chars,0,chars.length-1);
        return new String(chars);
    }

    public static void revStr(char[] chars, int i, int j) {
        while (i<j) {
            chars[i] ^= chars[j];
            chars[j] ^= chars[i];
            chars[i] ^= chars[j];
            i++;
            j--;
        }
    }
}
